package com.gxuwz.eschool;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.gxuwz.eschool.config.SpacesItemDecoration;
import com.gxuwz.eschool.fragment.MessageFragment;
//消息中心-系统通知
public class MessageForSystem extends AppCompatActivity {
    private HomeAdapter mAdapter;

    //需要适配的数据
    private String[] title = {"【支付中心】一卡通充值","【支付中心】一卡通充值","【支付中心】一卡通充值","【支付中心】一卡通充值","【支付中心】一卡通充值","【支付中心】一卡通充值","【支付中心】一卡通充值","【支付中心】一卡通充值"};
    private String[] money = {"￥500","￥100","￥200","￥60","￥100","￥200","￥200","￥200"};
    private String[] informationStyle = {"系统通知","系统通知","系统通知","系统通知","系统通知","系统通知","系统通知","系统通知"};
    private String[] time = {"一天前","2024-03-25","2024-03-01","2024-02-25","2024-02-01","2024-01-28","2024-01-11","2024-01-01"};
    private String[] information = {"农行支付，支付成功。","农行支付，支付成功。","农行支付，支付成功。","农行支付，支付成功。","农行支付，支付成功。","农行支付，支付成功。","农行支付，支付成功。","农行支付，支付成功。"};
    private RecyclerView mRecyclerView;
    private ImageView iv_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_for_system);
        iv_back = findViewById(R.id.iv_back);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent intent = new Intent(MessageForSystem.this, MessageFragment.class);
//                startActivity(intent);
                // 使用SupportFragmentManager来管理Fragment事务
                FragmentManager fragmentManager = getSupportFragmentManager();

                // 检查是否有Fragment可以回退
                if (fragmentManager.getBackStackEntryCount() > 0) {
                    fragmentManager.popBackStack(); // 返回上一个Fragment
                } else {
                    // 如果没有Fragment可以回退，可以结束当前Activity
                    finish();
                }
            }
        });
        mRecyclerView =(RecyclerView) findViewById(R.id.rv_list);
        //设置RecyclerView的item之间的边距
        int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.recycler_view_item_spacing);
        mRecyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new HomeAdapter();
        mRecyclerView.setAdapter(mAdapter);
    }
    class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder> {
        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(MessageForSystem.this).inflate(R.layout.message_list_item,null);
            MyViewHolder holder = new MyViewHolder(view);

            holder.tv_title = view.findViewById(R.id.tv_title);
            holder.tv_money = view.findViewById(R.id.tv_money);
            holder.tv_information_style = view.findViewById(R.id.tv_information_style);
            holder.tv_information_time = view.findViewById(R.id.tv_information_time);
            holder.tv_information = view.findViewById(R.id.tv_information);

            return holder;
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position) {
            holder.tv_title.setText(title[position]);
            holder.tv_money.setText(money[position]);
            holder.tv_information.setText(information[position]);
            holder.tv_information_time.setText(time[position]);
            holder.tv_information_style.setText(informationStyle[position]);
        }

        @Override
        public int getItemCount() {
            return money.length;
        }


        class MyViewHolder extends RecyclerView.ViewHolder{
            TextView tv_title,tv_money,tv_information_style,tv_information_time,tv_information;
            public MyViewHolder(View view) {
                super(view);
//                tv_title = findViewById(R.id.tv_title);
//                tv_money = findViewById(R.id.tv_money);
//                tv_information_style = findViewById(R.id.tv_information_style);
//                tv_information_time  = findViewById(R.id.tv_information_time);
//                tv_information = findViewById(R.id.tv_information);
            }
        }

    }

}